package com.ymttest.business.service;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;

import com.shop2cn.iapi.activitymgt.parameter.AddactivityBean;
import com.shop2cn.iapi.prodstock.parameter.InitProductActivityStockBean;
import com.shop2cn.iapi.prodstock.parameter.ProductActivityStockDto;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.Logger;
import com.ymttest.utils.YMTDateUtil;

public class GodProductStockCallService {
	
//	public static void sqCatalogStockChange_commandsync(String catalogId, String productId) {
//
//		YmatouEasyCall sqCatalogStockChangeCall = new YmatouEasyCall("", "POST", "JSON");
//		StringBuilder sqCatalogStockChangeString = new StringBuilder();
//
//		sqCatalogStockChangeString.append("{\"actionType\":\"CatalogStockChange\",");
//		sqCatalogStockChangeString.append("\"activityId\":0,");
//		sqCatalogStockChangeString.append("\"appId\":\"prodstock.iapi.shop2cn.com\",");
//		sqCatalogStockChangeString.append("\"catalogId\":\"" + catalogId + "\",");
//		sqCatalogStockChangeString.append("\"productId\":\"" + productId + "\",");
//		sqCatalogStockChangeString.append("\"transactionId\":0}");
//
//		sqCatalogStockChangeCall
//				.setUrl("http://productsynces.iapi.shop2cn.com/api/commandsync");
//
//		sqCatalogStockChangeCall.setData(sqCatalogStockChangeString.toString());
//
//		try {
//			sqCatalogStockChangeCall.callService();
//
//			Logger.comment(sqCatalogStockChangeCall.getReturnData());
//
//		} catch (Exception e) {
//
//			e.printStackTrace();
//		}
//	}
	
	public static void sqCatalogStockChange_invokemongocrud(String catalogId, String productId) {

		YmatouEasyCall sqCatalogStockChangeCall = new YmatouEasyCall("", "POST", "JSON");
		StringBuilder sqCatalogStockChangeString = new StringBuilder();

		sqCatalogStockChangeString.append("{\"actionType\":\"CatalogStockChange\",");
		sqCatalogStockChangeString.append("\"activityId\":0,");
		sqCatalogStockChangeString.append("\"appId\":\"prodstock.iapi.shop2cn.com\",");
		sqCatalogStockChangeString.append("\"catalogId\":\"" + catalogId + "\",");
		sqCatalogStockChangeString.append("\"productId\":\"" + productId + "\",");
		sqCatalogStockChangeString.append("\"transactionId\":0}");

		sqCatalogStockChangeCall
				.setUrl("http://productsync.iapi.shop2cn.com/api/cache/invokemongocrud");

		sqCatalogStockChangeCall.setData(sqCatalogStockChangeString.toString());

		try {
			sqCatalogStockChangeCall.callService();

			Logger.comment(sqCatalogStockChangeCall.getReturnData());

		} catch (Exception e) {

			e.printStackTrace();
		}
	}
	
	public static void InitProductActivityStock(AddactivityBean activityBean,String productId,int activityId,int stock) throws ClientProtocolException, IOException {
		InitProductActivityStockBean bean = new InitProductActivityStockBean();
		bean.setUserID(activityBean.getSellerId());
		bean.setProductID(productId);
		bean.setActivityID(activityId);
//		bean.setProductActivityId(1);
		bean.setBeginTime(YMTDateUtil.getFormatDateString(activityBean.getBeginTime(),YMTDateUtil.YMDTHMS_STRING));
		bean.setEndTime(YMTDateUtil.getFormatDateString(activityBean.getEndTime(),YMTDateUtil.YMDTHMS_STRING));
		bean.setActivityType(activityBean.getActivityType());
		bean.setStockType(0);
		bean.setActivityName(activityBean.getName());
		bean.setLimitNum(activityBean.getLimitNum());
//		ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(activityBean.getSellerId(),productId);
//		selectProductDetails.getCatalogList().forEach(a->{
//			ProductActivityStockDto productActivityStockDto = new ProductActivityStockDto();
//			productActivityStockDto.setCatalogId(a.getCatalogId());
//			productActivityStockDto.setStock(stock);
//			productActivityStockDto.setActivityPrice(a.geta);
//			activityBean.getProductList().get(0).getCatalogList().get(0).get
//	 	});
		
		activityBean.getProductList().get(0).getCatalogList().forEach(b->{
			ProductActivityStockDto productActivityStockDto = new ProductActivityStockDto();
			productActivityStockDto.setCatalogId(b.getCatalogId());
			productActivityStockDto.setStock(stock);
			productActivityStockDto.setActivityPrice(b.getDiscountPrice());
			productActivityStockDto.setAction(0);
			productActivityStockDto.setDiscountType(0);
			productActivityStockDto.setDiscount(b.getDiscount());
		});
		
		
//		bean.set
		
	}

	public static void main(String[] args) {
		
		GodProductStockCallService.sqCatalogStockChange_invokemongocrud("c9278579", "p5600990");
	}
}
